<?php
/*
PWision extension: Newspaper http://pw-newspaper.googlecode.com/
Copyright (C) 2009--12 Becheru Petru-Ioan

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
include_once("inc/PTable.inc");
include_once("inc/PSection.inc");
include_once("inc/Users.inc");
include_once("pw-newspaper.inc");
include_once('inc/BBCode.inc');

/** 	The pwision_newspaper_Article class is designed to display an article.
	*	\latexonly \label{PWision:Extensions:Newspaper:pwision_newspaper_Article} \index{extension} \index{newspaper} \index{article} \endlatexonly
	*	\brief the article section.
	*	\version 3.1.10
	*/
class pwision_newspaper_Article extends PSection
	{
	static $Month=array(
		1=>'January',
		2=>'February',
		3=>'March',
		4=>'April',
		5=>'May',
		6=>'June',
		7=>'July',
		8=>'August',
		9=>'September',
		10=>'October',
		11=>'November',
		12=>'December'
		);

	function getTitle()
		{
		return $this->ArticleInfo->Title;
		}
	function Head()
		{
		$ret=parent::Head();
		$ret
				->Insert(
					Object(new PSimpleTag("link"))
						->setAtr('href','/Feed')
						->setAtr('type','application/atom+xml')
						->setAtr('rel','alternate')
						->setAtr('title','Feed')
					);
		if($this->ArticleInfo->textAbstract)
		$ret
				->Insert(
					Object(new PSimpleTag("meta"))
						->setAtr("name","description")
						->setAtr("content",
							preg_replace(
								'`[[:space:]]+`',' ',
								$this->ArticleInfo->textAbstract
								)
						)
					);
		if($this->ArticleInfo->keywords || $this->ArticleInfo->authors)
		$ret
				->Insert(
					Object(new PSimpleTag("meta"))
						->setAtr("name","keywords")
						->setAtr("content",
							($this->ArticleInfo->keywords?implode(',',$this->ArticleInfo->keywords):'').','.
							($this->ArticleInfo->authors?implode(',',$this->ArticleInfo->authors):'')
							)
					)
				;
		$ret
				->Insert(
					El('script')
							->setAtr('type','text/javascript')
							->setAtr('src','https://apis.google.com/js/plusone.js')
						->Insert(new PText("
window.___gcfg = {lang: '".Main()->getLanguage()."'};

(function() {
	var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
	po.src = 'https://apis.google.com/js/plusone.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
"							))
					)
				;
		//Google Scholar meta tags: http://scholar.google.com/intl/en/scholar/inclusion.html#indexing
		if($this->ArticleInfo->authors)
			{
			$ret->Insert(
				Object(new PSimpleTag('meta'))
					->setAtr('name','citation_title')
					->setAtr('content',$this->ArticleInfo->Title)
				);
			$ret->Insert(
				Object(new PSimpleTag('meta'))
					->setAtr('name','DC.Language')
					->setAtr('content',($this->ArticleInfo->Language=='')?Main()->getLanguage():$this->ArticleInfo->Language)
				);
			foreach($this->ArticleInfo->authors as $authorKey=>$author)
				{
				$ret->Insert(
					Object(new PSimpleTag('meta'))
						->setAtr('name','citation_author')
						->setAtr('content',$author)
					);
				if($this->ArticleInfo->authorAffiliations && isset($this->ArticleInfo->authorAffiliations[$authorKey+1]))
				foreach($this->ArticleInfo->authorAffiliations[$authorKey+1] as $affiliationKey)
					$ret->Insert(
						Object(new PSimpleTag('meta'))
							->setAtr('name','citation_author_institution')
							->setAtr('content',$this->ArticleInfo->affiliations[$affiliationKey-1])
						);
				}
			
			$ret->Insert(
				Object(new PSimpleTag('meta'))
					->setAtr('name','citation_publication_date')
					->setAtr('content',
						$this->ArticleInfo->Year.'/'.
						$this->ArticleInfo->Month.'/'.
						$this->ArticleInfo->Day
						)
				);
			$ret->Insert(
				Object(new PSimpleTag('meta'))
					->setAtr('name','citation_journal_title')
					->setAtr('content',Main()->getFullTitle())
				);
			if($this->ArticleInfo->Volume)
			$ret->Insert(
				Object(new PSimpleTag('meta'))
					->setAtr('name','citation_volume')
					->setAtr('content',$this->ArticleInfo->Volume)
				);
			if($this->ArticleInfo->Issue)
			$ret->Insert(
				Object(new PSimpleTag('meta'))
					->setAtr('name','citation_issue')
					->setAtr('content',$this->ArticleInfo->Issue)
				);
			if($this->ArticleInfo->firstPage)
			$ret->Insert(
				Object(new PSimpleTag('meta'))
					->setAtr('name','citation_firstpage')
					->setAtr('content',$this->ArticleInfo->firstPage)
				);
			if($this->ArticleInfo->lastPage)
			$ret->Insert(
				Object(new PSimpleTag('meta'))
					->setAtr('name','citation_lastpage')
					->setAtr('content',$this->ArticleInfo->lastPage)
				);
			if($this->ArticleInfo->pdfURL)
			$ret->Insert(
				Object(new PSimpleTag('meta'))
					->setAtr('name','citation_pdf_url')
					->setAtr('content',$this->ArticleInfo->pdfURL)
				);
			}
			if(Main()->getPublisher())
			$ret->Insert(
				Object(new PSimpleTag('meta'))
					->setAtr('name','DC.publisher')
					->setAtr('content',Main()->getPublisher())
				);
		//Open Graph meta tags
		$ret->Insert(
			Object(new PSimpleTag('meta'))
				->setAtr('property','og:url')
				->setAtr('content','http://'.$_SERVER['HTTP_HOST'].'/('.$this->ArticleInfo->ID.')')
			);
		$ret->Insert(
			Object(new PSimpleTag('meta'))
				->setAtr('property','og:title')
				->setAtr('content',$this->ArticleInfo->Title)
			);
		$ret->Insert(
			Object(new PSimpleTag('meta'))
				->setAtr('property','og:type')
				->setAtr('content','article')
			);
		$ret->Insert(
			Object(new PSimpleTag('meta'))
				->setAtr('property','og:site_name')
				->setAtr('content',Main()->getFullTitle())
			);
		if($this->ArticleInfo->coverURL)
		$ret->Insert(
			Object(new PSimpleTag('meta'))
				->setAtr('property','og:image')
				->setAtr('content',$this->ArticleInfo->coverURL)
			);
		$ret->Insert(
			Object(new PSimpleTag('meta'))
				->setAtr('property','og:published_time')
				->setAtr('content',
					$this->ArticleInfo->Year.'/'.
					$this->ArticleInfo->Month.'/'.
					$this->ArticleInfo->Day
					)
			);
	return $ret;
		}
	/// article info
	public $ArticleInfo;
	/**
		*	\brief display a TValue list.
		*	\version 2.3.2
		*	\param $array list
		*	\param $separator separation string between items
		*	\param $disable_translate true if you want that the ul element no to be translated by the webpage translate system
		*	\return an ul element
		*/
	static function ArticleTagListDraw($arr=array(),$second_array=null,$separator=',&nbsp; ',$last_separator=". ",$disable_translate=false,$disable_link=false,$ul=null,$li=null)
		{
		if($ul===null)
		$ul=Object(new PElement("span"))->setAtr('class','KwSCloud');
		if($li===null)
		$li=Object(new PElement("span"));
			if($disable_translate)$li->setAtr('class','notranslate');
		$ret=new PStructure($li,$ul);
		if(count($arr))
				{
				foreach($arr as $key=>$TValue)
					{
					$kid=$ret->newKid();
					if(!$disable_link)
							$kid
								->Insert(
									Sections::Link2(
										'KeywordSearch',
										lang("Search for")." [ $TValue ]",
										$TValue,
										Object(new PURLAttributes)
											->setAtr('kw',$TValue)
										)
											->setAtr('class','kw')
											->setAtr('rel','nofollow')
									);
						else
							$kid->Insert(new PText($TValue));
					if($second_array && array_key_exists($key+1,$second_array))
						{
						$rels=El('sup');
						foreach(array_reverse($second_array[$key+1]) as $rel)
							{
							$rels
								->Insert(new PText($rel))
								->Insert(new PText($separator) )
								;
							}
						$rels->Pop();
						$kid
							->Insert(new PText('&#8288;'))//Inhibit Line-break: word joiner
							->Insert($rels);
						}
					$kid
						->Insert(new PText($separator) )
						;
					}
				$ret->Last()->Pop();//remove the last separator
				$ret->Last()
						->Insert(new PText($last_separator) )
					;
				}
			else return null;
		return $ret;
		}
	function setParams()
		{
		$this
			->addParam('ID','/^[0-9]{1,10}$/','')
			->addParam('redirect','`^[0-9]$`','')
			;
		}
	function if_parameters_are_set()
		{
		$this->ArticleInfo=NewsPaper::getArticleInfo($_REQUEST['ID']);
		if( $this->ArticleInfo==null )
			throw new PSection_ParamNCheck('Article with ID '.$_REQUEST['ID'].' does not exist!');
		parent::if_parameters_are_set();
		if($_SERVER['REQUEST_URI']!=$this->URLPath)
			{
			header('HTTP/1.1 301 Moved Permanently');
			header('Location: http://'.$_SERVER['SERVER_NAME'].$this->URLPath
				); /* Redirect browser */
			exit;
			}
		}
	function if_not_all_parameters_are_set()
		{
		if(!$this->wasParamSet('ID'))$_REQUEST['ID']=1;
		$this->if_parameters_are_set();
		if($this->getParam('redirect')!='0' || $_SERVER['REQUEST_URI']!=$this->URLPath)
			{
			header('HTTP/1.1 301 Moved Permanently');
			header('Location: http://'.$_SERVER['SERVER_NAME'].$this->URLPath
				); /* Redirect browser */
			exit;
			}
		}

	/**	Transforms a text by replacing each non-latin char and space with dash.
		*	\brief transform a text to latin script.
		*	\version 1.0.2
		*	\param $text input text
		*	\return the latin text
		*/
	static protected function LatinText($text)
		{
		return BBCode::repeat_replace(
			array(
				'`[&][#]258;`' => 'A'//Ă
				,'`[&][#]259;`' => 'a'//ă
				,'`[&][#]194;`' => 'a'//Â
				,'`[&][#]226;`' => 'a'//â
				,'`[&][#]536;`' => 'S'//Ș
				,'`[&][#]537;`' => 's'//ș
				,'`[&][#]350;`' => 'S'//Ş
				,'`[&][#]351;`' => 's'//ş
				,'`[&][#]538;`' => 'T'//Ț
				,'`[&][#]539;`' => 't'//ț
				,'`[&][#]354;`' => 't'//Ţ
				,'`[&][#]355;`' => 't'//ţ
				,'`[&][#]206;`' => 'i'//Î
				,'`[&][#]238;`' => 'i'//î
				,'`[&][#]?[0-9]+;`' => '-'
				,'`[^a-z0-9()]`i' => '-'
				,'`[-]+`' => '-'
				,'`[-]$`' => ''
				),
			$text
			);
		}

	protected function ConstructLocation()
		{
		$this->URLPath='';
		$this->theLocation=new PContent;
		if($this->ArticleInfo->owner_path)
			{
			foreach($this->ArticleInfo->owner_path as $owner)
				{
				$this->URLPath=
					$this->URLPath.
					'/('.$owner['ID'].')'.
					$this->LatinText($owner['Title']);
				$this->theLocation
					->Insert( new PText("/") )
					->Insert(
						El('a')
								->setAtr('href',$this->URLPath)
								->setAtr('title',$owner['Title'])
								->setAtr('class','Article')
							->Insert(new PText($owner['Title']))
						)
					;
				}
			}
			else
				{
				$this->theLocation
					->Insert( new PText("&rsaquo; ") )
					->Insert(
						El('a')
								->setAtr('href',
									'/('.$this->ArticleInfo->ID.')'.
									$this->LatinText($this->ArticleInfo->Title)
									)
								->setAtr('title',$this->ArticleInfo->Title)
								->setAtr('class','Article')
							->Insert(new PText($this->ArticleInfo->Title))
						)
					;
				}
		$this->URLPath=
			$this->URLPath.
			'/('.$this->ArticleInfo->ID.')'.
			$this->LatinText($this->ArticleInfo->Title);
		$this->theLocation->InsertFirst( Sections::Link2('Root') );
		}

	function getDescription()
		{
		$ret= new PContent;
		$local_menu=null;
		if( $_SESSION['userID']>0 )
			{
			$commands=null;//PContent
			if(Users::hasAccess($_SESSION['userID'],'CreateArticle'))
				{
				if(!$commands)$commands=new PContent;
				//create a clone
				$commands->Insert(
					El('div')
						->Insert(
							Sections::Link2(
								'CreateArticle',
								'',
								lang('Create a clone article'),
								Object(new PURLAttributes)
									->setAtr('clone',$this->getParam('ID') )
								)
								->setAtr('target','_blank')
							)
					);
				//create default subarticle
				$commands->Insert(
					El('div')
						->Insert(
							Sections::Link2(
								'CreateArticle',
								'',
								lang('Create a subarticle'),
								Object(new PURLAttributes)
									->setAtr('subarticleID',$this->getParam('ID') )
								)
								->setAtr('target','_blank')
							)
					);
				//create clone subarticle
				$commands->Insert(
					El('div')
						->Insert(
							Sections::Link2(
								'CreateArticle',
								'',
								lang('Create a clone subarticle'),
								Object(new PURLAttributes)
									->setAtr('subarticleID',$this->getParam('ID') )
									->setAtr('clone',$this->getParam('ID') )
								)
								->setAtr('target','_blank')
							)
					);
				}
			if(Users::hasAccess($_SESSION['userID'],'EditArticle'))
				{
				if(!$commands)$commands=new PContent;
				$commands->Insert(
					El('div')
						->Insert(
							Sections::Link2(
								'EditArticle',
								'',
								lang('Edit this article'),
								Object(new PURLAttributes)
									->setAtr('ID',$this->getParam('ID') )
								)
							)
					);
				}
			if($commands)
				{
				if(!$local_menu)$local_menu=El('div')->setAtr('class','intro');
					else $local_menu->Insert( sEl('hr'));
				$local_menu
					->Insert( $commands );
				}
			}
		if(( $authors_span=pwision_newspaper_Article::ArticleTagListDraw( $this->ArticleInfo->authors,$this->ArticleInfo->authorAffiliations,',&nbsp; ','. ',true ) ))
			$ret->Insert(
					El('dl')
							->setAtr('class','authors')
						->Insert(
							El('dt')
								->Insert( new PText(lang('authors').':') )
							)
						->Insert( 
							El('dd')
								->Insert( new PText($authors_span) )
							)
					);
		if(( $affiliations_span=pwision_newspaper_Article::ArticleTagListDraw( $this->ArticleInfo->affiliations,null,'; ','. ',false,true,El('ol'), El('li') ) ))
			$ret->Insert(
					El('dl')
							->setAtr('class','affiliations')
						->Insert(
							El('dt')
								->Insert( new PText(lang('affiliations').':') )
							)
						->Insert( 
							El('dd')
								->Insert( new PText($affiliations_span) )
								->setAtr('lang',$this->ArticleInfo->Language)
							)
					);
		if(( $keywords_span=pwision_newspaper_Article::ArticleTagListDraw( $this->ArticleInfo->keywords ) ))
			$ret
				->Insert(
					El('dl')
							->setAtr('class','keywords')
						->Insert(
							El('dt')
								->Insert( new PText(lang('keywords').':') )
							)
						->Insert( 
							El('dd')
								->Insert( new PText($keywords_span) )
								->setAtr('lang',$this->ArticleInfo->Language)
								->setAtr('lang',$this->ArticleInfo->KwLanguage)
							)
					);
		if(( $classifications_span=pwision_newspaper_Article::ArticleTagListDraw( $this->ArticleInfo->classifications ) ))
			$ret
				->Insert(
					El('dl')
							->setAtr('class','classifications')
						->Insert(
							El('dt')
								->Insert( new PText(lang('classifications').':') )
							)
						->Insert( 
							El('dd')
								->Insert( new PText($classifications_span) )
								->setAtr('lang',$this->ArticleInfo->Language)
								->setAtr('lang',$this->ArticleInfo->KwLanguage)
							)
					);
		$dl=
		El('dl')
			/*
			->Insert(
				El('dt')
					->Insert(PTextlang(''))
				)
			->Insert(
				El('dd')
					->Insert(new PText($sub_art[''].';'))
				);
			*/
			;
		$dl
			->Insert(
				El('dd')
						->setAtr('class','notranslate')
					->Insert(new PText(Main()->getTitle()))
				);
		if($this->ArticleInfo->Volume)
			$dl
				->Insert(
					El('dt')
						->Insert(PTextlang('volume'))
					)
				->Insert(
					El('dd')
						->Insert(new PText($this->ArticleInfo->Volume))
					);
		if($this->ArticleInfo->Issue)
			$dl
				->Insert(
					El('dt')
						->Insert(PTextlang('issue'))
					)
				->Insert(
					El('dd')
						->Insert(new PText($this->ArticleInfo->Issue))
					);
		if($this->ArticleInfo->firstPage||$this->ArticleInfo->lastPage)
			{
			$dl
				->Insert(
					El('dt')
						->Insert(
							PTextlang(
								$this->ArticleInfo->lastPage?'pages':'page'
								)
							)
					);
			$dd=El('dd');
				if($this->ArticleInfo->firstPage)
					$dd
						->Insert(new PText($this->ArticleInfo->firstPage));
				if($this->ArticleInfo->firstPage && $this->ArticleInfo->lastPage)
					$dd
						->Insert(new PText('&ndash;'));
				if($this->ArticleInfo->lastPage)
					$dd
						->Insert(new PText($this->ArticleInfo->lastPage));
			$dl->Insert($dd);
			}
		if($this->ArticleInfo->Issue && $this->ArticleInfo->Year && $this->ArticleInfo->Month && $this->ArticleInfo->Day )
			{
			$dl
				->Insert(
					El('dt')
// 						->Insert(PTextlang('date'))
					)
				->Insert(
					El('dd')
						->Insert(
							new PText(
								$this->ArticleInfo->Day.' '.
								lang(pwision_newspaper_Article::$Month[(int)$this->ArticleInfo->Month]).' '.
								$this->ArticleInfo->Year
								)
							)
					)
				;
			}
// 		//links
// 		if(
// 			$this->ArticleInfo->pdfURL// other links may follow
// 			)
// 			{
// 			$links=El('dl')
// 						->Insert(
// 							El('dt')
// 								->Insert(new PText(lang('links').':') )
// 							)
// 						;
// 			if($this->ArticleInfo->pdfURL)
// 				$links->Insert(
// 							El('dd')
// 								->Insert(
// 									El('a')
// 										->setAtr('href',$this->ArticleInfo->pdfURL)
// 										->setAtr('target','_blank')
// 										->Insert(
// 											El('span')
// 												->Insert(PTextlang('PDF'))
// 											)
// 									)
// 							);
// 			$ret->Insert($links);
// 			}
		if($this->ArticleInfo->authors)
			$ret->InsertFirst(
					Sections::Link2(
						'Cite',
						lang('article citation forms'),
						'',
						Object(new PURLAttributes)
							->setAtr('articleID',$this->ArticleInfo->ID)
							->setAtr('form','1')//simple text
						)
							->setAtr('rel','nofollow')
						->Insert($dl)
				);
		if($this->ArticleInfo->coverURL)
		$ret->InsertFirst(
				El('a')
						->setAtr('class','cover')
						->setAtr('href',$this->ArticleInfo->pdfURL)
					->Insert(
						Object(new PSimpleTag('img'))
								->setAtr('src',$this->ArticleInfo->coverURL)
								->setAtr('class','cover')
						)
					->Insert(
						Object(new PSimpleTag('img'))
								->setAtr('src',$this->ArticleInfo->coverURL)
								->setAtr('class','coverbk')
						)
			);
		if($this->ArticleInfo->pdfURL)
			$ret->InsertFirst(
				Object(new PContent)
					->Insert(
							El('a')
									->setAtr('class','PDFBigLink')
									->setAtr('href',$this->ArticleInfo->pdfURL)
									->setAtr('target','_blank')
									->setAtr('title',lang('PDF'))
								->Insert(
									El('span')
										->Insert(PTextlang('PDF version'))
									)
							)
				);
		$ret->InsertFirst($local_menu);
		return $ret;
		}
	function	Chapter0Title()
		{
		return 
			El('span')
					->setAtr('lang',$this->ArticleInfo->Language)
				->Insert(new PText($this->ArticleInfo->Title.' '))
				->Insert(
					El('g:plusone')//->setAtr('size','medium')
					)
				->Insert(
					El('a')
							->setAtr(
								'href',
								'https://www.facebook.com/sharer.php?u='.
									urlencode(
										'http://'.$_SERVER['HTTP_HOST'].'/('.$this->ArticleInfo->ID.')'
										)
								)
							->setAtr('target','_blank')
							->setAtr('title',lang('Click here to post on Facebook'))
							->Insert(
								El('span')
									->setAtr('class','fbShare')
								)
					)
				;
		}
	function	Chapter0()
		{
		return parent::Chapter0()
				->Insert(
					Main()->LongAdd()
					)
				->Insert(
					Main()->TranslateElement('ArticleTitleTranslate')
					)
				;
		}
/*	function	Chapter1Title()
		{
		return $this->ArticleInfo->sub_articles?PTextlang('Content:'):parent::Chapter1Title();
		}*/
	function	Chapter1()
		{
		if(  count($this->ArticleInfo->sub_articles) == 0  )
			return null;
		$content=Object(new PTable(false))
				->setAtr('id','content')
			->setCaptionText ( lang('Content:') )
			;
		foreach($this->ArticleInfo->sub_articles as $sub_art)
			{
			$content->AddRow();
			$content
				->AddCell()
						->setAtr('class','authors')
					->Insert(pwision_newspaper_Article::ArticleTagListDraw( $sub_art['Authors'],null,', ','',true ))
				;
			$dl=
			El('dl')/*
				->Insert(
					El('dt')
						->Insert(PTextlang(''))
					)
				->Insert(
					El('dd')
						->Insert(new PText($sub_art[''].';'))
					);
				*/
				;
			if($sub_art['Volume'])
				$dl
					->Insert(
						El('dt')
							->Insert(PTextlang('volume'))
						)
					->Insert(
						El('dd')
							->Insert(new PText($sub_art['Volume']))
						);
			if($sub_art['Issue'])
				$dl
					->Insert(
						El('dt')
							->Insert(PTextlang('issue'))
						)
					->Insert(
						El('dd')
							->Insert(new PText($sub_art['Issue']))
						);
			if($sub_art['firstPage']||$sub_art['lastPage'])
				{
				$dl
					->Insert(
						El('dt')
							->Insert(PTextlang(
								$sub_art['lastPage']?'pages':'page'
								))
						);
				$dd=El('dd');
					if($sub_art['firstPage'])
						$dd
							->Insert(new PText($sub_art['firstPage']));
					if($sub_art['firstPage']&&$sub_art['lastPage'])
						$dd
							->Insert(new PText('&ndash;'));
					if($sub_art['lastPage'])
						$dd
							->Insert(new PText($sub_art['lastPage']));
				$dl->Insert($dd);
				}
// 			if($sub_art['Issue'])
// 				{
// 				$dd=El('dd');
// 				$dd
// 					->Insert(
// 						new PText(
// 							$this->ArticleInfo->Day.' '.
// 							lang(pwision_newspaper_Article::$Month[(int)$this->ArticleInfo->Month]).' '.
// 							$this->ArticleInfo->Year
// 							)
// 						)
// // 					->Insert(new PText(','));
// 					;
// 				$dl->Insert($dd);
// 				}
			$cover=null;
			if($sub_art['coverURL'])
				$cover=El('span')
						->setAtr('class','cover')
					->Insert(
						Object(new PSimpleTag('img'))
								->setAtr('src',$sub_art['coverURL'])
								->setAtr('class','cover')
						)
					->Insert(
						Object(new PSimpleTag('img'))
								->setAtr('src',$sub_art['coverURL'])
								->setAtr('class','coverbk')
						)
				;
			$EditArticle=null;
			if(Users::hasAccess($_SESSION['userID'],'EditArticle'))
				{
				$EditArticle=
					Sections::Link2(
						'EditArticle',
						'',
						lang('Edit this article'),
						Object(new PURLAttributes)
							->setAtr('ID', $sub_art['ID'] )
						);
				}
			$content
				->AddCell()
						->setAtr('class','title')
					->Insert(
						El('a')
								->setAtr(
									'href',
									$this->URLPath.
									'/('.$sub_art['ID'].')'.$this->LatinText($sub_art['Title'])
									)
								->setAtr('title',$sub_art['Title'])
								->setAtr('class','Article')
								->setAtr('lang',$sub_art['Language'])
							->Insert(new PText($sub_art['Title']))
							->InsertFirst($cover)
						)
					->Insert($EditArticle)
					->Insert($dl)
				;
			}
		return parent::Chapter1()->Insert($content);
		}

	function	Chapter2()
		{
		$abstract=null;
		$absTitle=null;
		if($this->ArticleInfo->absTitle)
			$absTitle=El('h5')->Insert(	new PText($this->ArticleInfo->absTitle) );
		if($this->ArticleInfo->textAbstract)
		$abstract=
			Object(new PContent)
				->Insert(
					El('h4')
						->Insert(
							PTextlang('Abstract')
							)
					)
				->Insert(
					El('span')
							->setAtr('class','notranslate')
							->setAtr('id','abstract')
							->setAtr('lang',
								($this->ArticleInfo->absLanguage=='')?
									Main()->getLanguage()
									:$this->ArticleInfo->absLanguage
									)
						->Insert($absTitle)
						->Insert(
							El('p')
								->Insert(new PText(
									preg_replace(
										'`(\n|\r)+`','<br/>',
										$this->ArticleInfo->textAbstract
										)
									))
							)
					)
			;
		$PDF=null;
		if($this->ArticleInfo->pdfURL)
				if(	
						count($this->ArticleInfo->sub_articles)>0 ||
						$this->ArticleInfo->text != ""
						)
						$PDF=Object(new PContent)
							->Insert(
								El('div')
									->Insert(
										El('a')
												->setAtr('class','PDFBigLink')
												->setAtr('href',$this->ArticleInfo->pdfURL)
												->setAtr('target','_blank')
												->setAtr('title',lang('PDF'))
											->Insert(
												El('span')
													->Insert(PTextlang('PDF version'))
												)
										)
								)
							;
					else
						$PDF=El('embed')
							->setAtr('src',$this->ArticleInfo->pdfURL)
							->setAtr('width',800)
							->setAtr('height',600)
							->setAtr('type','application/pdf')
							;
		return 
			Object(new PContent)
				->Insert($abstract)
				->Insert(new PText($this->ArticleInfo->HTML ) )
				->Insert($PDF)
				;
		}

	function	Chapter3Title()
		{
		return $this->ArticleInfo->owners?PTextlang('This article is part of the following collections:'):parent::Chapter3Title();
		}
	function	Chapter3()
		{
		if(  count($this->ArticleInfo->owners) == 0  )
			return null;
		$ul=new PStructure(
			new PElement('li'),
			new PElement('ul')
			);
		foreach($this->ArticleInfo->owners as $owner)
			$ul->newKid()->Insert(
				Sections::Link2(
					'Article',
					$owner['Title'],
					$owner['Title'],
					Object(new PURLAttributes)
						->setAtr('ID',$owner['ID'])
					)
				);
		return parent::Chapter3()
			->Insert($ul)
			;
		}

	function	Chapter4Title()
		{
		return $this->ArticleInfo->logs?PTextlang('Logs:'):parent::Chapter4Title();
		}
	function	Chapter4()
		{
		if(  count($this->ArticleInfo->logs) == 0  )
			return null;
		$ul=new PStructure(
			new PElement('li'),
			new PElement('ul')
			);
		foreach($this->ArticleInfo->logs as $log)
			$ul->newKid()->Insert(new PText($log));
		return parent::Chapter4()
			->Insert($ul)
			;
		}

	}
?>